package com.example.prison.mapper;

import com.example.prison.entity.DefenceArea;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
* @author jiang
* @description 针对表【defence_area】的数据库操作Mapper
* @createDate 2023-06-02 12:33:20
* @Entity com.example.prison.entity.DefenceArea
*/
@Mapper
public interface DefenceAreaMapper extends BaseMapper<DefenceArea> {

    @Select("select * from defence_area a order by a.id desc")
    List<DefenceArea> get();

    @Insert("insert into defence_area(number, address, status) " +
            "values (#{number}, #{address}, #{status})")
    int add(DefenceArea area);

    @Delete("<script>delete from defence_area where id in <foreach collection=\"ids\" item=\"item\" open=\"(\" separator=\",\" close=\")\">#{item} </foreach> </script>")
    void deleteDefenceArea(@Param("ids") Integer[] ids);

    @Delete("delete from defence_area where id=#{id}")
    void deleteDefenceAreaById(@Param("id") Integer id);

    @Update("update defence_area set number=#{user.number}, address=#{user.address}, status=#{user.status} where id = #{id}")
    int updateDefenceArea(DefenceArea user, Integer id);

    @Update("update defence_area set number=#{user.number}, address=#{user.address}, status=#{user.status} where id = #{id}")
    int updateDefenceAreaFail(DefenceArea user,Integer id);

    @Select("select * from defence_area where id=#{id}")
    DefenceArea getById(@Param("id") Integer id);

    @Select("select * from defence_area where number like concat('%',#{number},'%') order by id desc")
    List<DefenceArea> getByNumber(@Param("number") String number);

    @Select("select * from defence_area where number=#{number} order by id desc")
    List<DefenceArea> getDefenceAreaByNumber(@Param("number") String number);

    @Select("select * from defence_area where number=#{number} order by id desc")
    DefenceArea getOneByNumber(@Param("number") String number);

    @Select("select * from defence_area where status=#{status} order by id desc")
    List<DefenceArea> getByStatus(@Param("status") String status);

}




